<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>redquadh.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>red_model&nbsp;</span>=&nbsp;<span class=defun_name>redquadh</span>(<span class=defun_in>model</span>)<br>
<span class=h1>%&nbsp;REDQUADH&nbsp;reduced&nbsp;SVM&nbsp;classifier&nbsp;with&nbsp;homogeneous&nbsp;quadratic&nbsp;kernel.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;redquadh(model)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;It&nbsp;uses&nbsp;reduced&nbsp;set&nbsp;techique&nbsp;(Burges)&nbsp;to&nbsp;compute&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;simpler&nbsp;SVM&nbsp;binary&nbsp;rule&nbsp;with&nbsp;homogeneous&nbsp;quadratic&nbsp;kernel&nbsp;(x'*y)^2.</span><br>
<span class=help>%&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Input:</span></span><br>
<span class=help>%&nbsp;&nbsp;model.Alpha&nbsp;[nsv&nbsp;x&nbsp;1]&nbsp;Weights&nbsp;of&nbsp;kernel&nbsp;expansion.</span><br>
<span class=help>%&nbsp;&nbsp;model.b&nbsp;[scalar]&nbsp;Bias.</span><br>
<span class=help>%&nbsp;&nbsp;model.sv.X&nbsp;[dim&nbsp;x&nbsp;nsv]&nbsp;Support&nbsp;vectors.</span><br>
<span class=help>%&nbsp;&nbsp;model.options.ker&nbsp;=&nbsp;'poly'</span><br>
<span class=help>%&nbsp;&nbsp;model.options.arg&nbsp;=&nbsp;[2&nbsp;0]</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Output:</span></span><br>
<span class=help>%&nbsp;&nbsp;red_model.Alpha&nbsp;[new_nsv&nbsp;x&nbsp;1]&nbsp;New&nbsp;weights.</span><br>
<span class=help>%&nbsp;&nbsp;red_model.b&nbsp;[scalar]&nbsp;Bias.</span><br>
<span class=help>%&nbsp;&nbsp;red_model.sv.X&nbsp;[dim&nbsp;x&nbsp;new_nsv]&nbsp;New&nbsp;"support&nbsp;vectors".</span><br>
<span class=help>%&nbsp;&nbsp;...</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;trn&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;model&nbsp;=&nbsp;smo(trn,{'ker','poly','arg',[2&nbsp;0],'C',10});</span><br>
<span class=help>%&nbsp;&nbsp;red_model&nbsp;=&nbsp;redquadh(&nbsp;model&nbsp;);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;ppatterns(trn);&nbsp;psvm(model);</span><br>
<span class=help>%&nbsp;&nbsp;figure;&nbsp;ppatterns(trn);&nbsp;psvm(red_model);</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;28-nov-2003,&nbsp;VF</span><br>
<br>
<hr>
dim=size(model.sv.X,1);<br>
nsv&nbsp;=&nbsp;model.nsv;<br>
<br>
S&nbsp;=&nbsp;zeros(dim,dim);<br>
<br>
<span class=keyword>for</span>&nbsp;i=1:dim,<br>
&nbsp;&nbsp;<span class=keyword>for</span>&nbsp;j=i:dim,<br>
&nbsp;&nbsp;&nbsp;&nbsp;S(i,j)&nbsp;=&nbsp;(model.sv.X(i,:).*model.sv.X(j,:)&nbsp;)*model.Alpha(:);<br>
&nbsp;&nbsp;&nbsp;&nbsp;S(j,i)&nbsp;=&nbsp;S(i,j);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>end</span><br>
<br>
[V,D]&nbsp;=&nbsp;eig(S);<br>
D=real(diag(D));<br>
[dummy,inx]&nbsp;=&nbsp;sort(-abs(D));<br>
D=D(inx);<br>
V=V(:,inx);<br>
<br>
inx&nbsp;=&nbsp;find(D&nbsp;~=&nbsp;0);<br>
<br>
red_model.nsv&nbsp;=&nbsp;length(inx);<br>
red_model.Alpha&nbsp;=&nbsp;zeros(red_model.nsv,1);<br>
red_model.b&nbsp;=&nbsp;model.b;<br>
red_model.sv.X&nbsp;=&nbsp;zeros(dim,red_model.nsv);<br>
red_model.options&nbsp;=&nbsp;model.options;<br>
red_model.classifier&nbsp;=&nbsp;<span class=quotes>'svmclass'</span>;<br>
red_model.eigval&nbsp;=&nbsp;D(inx);<br>
<br>
cnt&nbsp;=&nbsp;0;<br>
<span class=keyword>for</span>&nbsp;i=inx(:)',<br>
&nbsp;&nbsp;cnt&nbsp;=&nbsp;cnt+1;<br>
&nbsp;&nbsp;red_model.sv.X(:,cnt)&nbsp;=&nbsp;V(:,i);<br>
&nbsp;&nbsp;red_model.Alpha(cnt)&nbsp;=&nbsp;D(i)/(red_model.sv.X(:,cnt)'*red_model.sv.X(:,cnt));<br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<br>
<br>
</code>
